<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class ReportController extends AdminbaseController {

      //用户信息 列表
    function report_lst(){

        $nickname = trim(I("nickname"));
        $phone = trim(I("phone"));
        $stime = I("kaishi");
        $etime = I("jieshu");

        $p = I("p");
        $where = " 1 ";
        if(!empty($nickname)){
            $where .= " and ac.nickname like '%{$nickname}%' ";
        }
        if(!empty($phone)){
            $where .= " and ac.phone like '%{$phone}%' ";
        }
        if (!empty($stime)) {
            $time1 = strtotime($stime." "."00:00:00");
            $where .= " and {$time1} <= re.ctime";
        }
        if (!empty($etime)) {
            $time2 = strtotime($etime." "."23:59:59");
            $where .= " and re.ctime <= {$time2}";
        }

        $count =  M("report re") ->join(" join " . C("DB_PREFIX") . "account ac on re.account_id = ac.id")->where($where)->count();
        if($count==0){
            $p = 0;
        }else{
            if(empty($p)){
                $p = 1;
            }
        }
        $totalpage = ceil($count/10);
        $page = $this->page($count,10);
        $sd = ($p-1)*10;
//               var_dump($stime);die;
        $data = M("report re")
            ->join(" join " .C("DB_PREFIX") . "account ac on re.account_id = ac.id")
            ->where($where)
            ->field("re.*,ac.nickname,ac.phone")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->order("id desc")
            ->select();
        foreach($data as $v){
            $beijubao[] = $v['beijubao_id'];
        }
          $beijubaos = implode(',',$beijubao);
        if($beijubaos){
            $yonghu = M("account")->where("id in ($beijubaos)")->select();
        }
        foreach($data as $k=>$v){
            foreach($yonghu as $kk=>$vv){
                if($v['beijubao_id'] == $vv['id']){
                    $data[$k]["beijubao"] = $vv['nickname'];
                    $data[$k]['mobile'] = $vv['phone'];
                }
            }
        }


        $this->assign("data",$data);
        $this->assign("nickname",$nickname);
        $this->assign("phone",$phone);
        $this->assign("stime_kaishi",$stime);
        $this->assign("etime_jieshu",$etime);
        $this->assign("page", $page->show('Admin'));
        $this->assign("p",$p);
        $this->assign("sd",$sd);
        $this->assign("totalpage",$totalpage);
        $this->display();
    }



}